<template>
	<view :class="config.style">
		<view class="search">
			<view class="uni-form-item uni-column">
				<uni-icons type="search" size="18" class="search-icon"></uni-icons>
				<input class="uni-input search-input" confirm-type="search" placeholder="搜索商品" @confirm="startSearch"/>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: true, //加载中
				config: {}, //全局配置数据
			}
		},
		onLoad(option) { //option为object类型，会序列化上个页面传递的参数
			
		},
		methods: {
			/**
			 * 获取配置
			 */
			getConfig: function(){
				let that = this
				return new Promise((resolve, reject) => {
					const config = uni.getStorageSync('config');
					if(config){
						that.config = config
						resolve(config)
					}else{
						//获取全局配置
						let url = '';
							//#ifdef MP-WEIXIN
							url = 'entry/wxapp/config'
							//#endif
							//#ifdef H5
							url = 'entry/site/config'
							//#endif
						this.util.request({
							url : url,
							data: {
								'action' : ''
							},
							success: function (res) {
								console.log(res.data);
								if (res.data.code == 200) {
									that.config = res.data.data
								}
								resolve(res.data)
							}
						})
					}
				})
			},

			/**
			 * 执行搜索
			 * @param {Object} e
			 */
			startSearch: function(e){
				console.log(e)
				let keyword = e.detail.value
				
				let url = '../goods/lists?keyword=' + keyword
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			}
		}
	}
</script>

<style lang="scss">
	.search {
		position: relative;
		padding: 10rpx 20rpx;
		.search-input {
			border: 2rpx solid #fff;
			background-color: #f2f2f2;
			border-radius: 30rpx;
			padding: 12rpx 12rpx 12rpx 60rpx;
			font-size: 28rpx;
		}
		.search-icon {
			position: absolute;
			left: 36rpx;
			top: 24rpx;
			color: #000;
		}
	}
</style>
